//
//  MusicDetailTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/17.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "MusicDetailTableViewCell.h"
#import <UIImageView+WebCache.h>


#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation MusicDetailTableViewCell
- (void)dealloc
{
    [_image release];
    [_titleLabel release];
    [_detailLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.image = [UIImageView new];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.detailLabel = [UILabel new];
    self.detailLabel.textColor = [UIColor grayColor];
    self.detailLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.detailLabel];
    [_detailLabel release];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.image.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(10), SCREEN_WIDTH / 3, HEIGHT_PRO(80));
    self.titleLabel.frame = CGRectMake(self.image.frame.origin.x + self.image.frame.size.width + WIDTH_PRO(20), self.image.frame.origin.y + HEIGHT_PRO(10), SCREEN_WIDTH - self.image.frame.size.width - WIDTH_PRO(30), HEIGHT_PRO(20));
    self.detailLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + HEIGHT_PRO(20), self.titleLabel.frame.size.width, HEIGHT_PRO(20));
}

-(void)setMusicModel:(AsiaNewSongModel *)musicModel
{
    if (_musicModel != musicModel) {
        [_musicModel release];
        _musicModel = [musicModel retain];
    }
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:musicModel.picUrl] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    self.titleLabel.text = musicModel.name;
    self.detailLabel.text = musicModel.desc;
    
}

+(MusicDetailTableViewCell *)musicDetailTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentify = @"musicDetailSong";
    MusicDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[MusicDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
